package com.jxt.myjxtmanager.ui.fragment;

import android.text.TextUtils;

import com.inqbarna.tablefixheaders.TableFixHeaders;
import com.jxt.myjxtmanager.BaseFragment;
import com.jxt.myjxtmanager.R;
import com.jxt.myjxtmanager.entity.StuClassShowBean;
import com.jxt.myjxtmanager.ui.inter.StuClassShowInter;
import com.jxt.myjxtmanager.ui.presenter.StuClassShowPresenter;
import com.jxt.myjxtmanager.ui.tableadapter.StuClassNexusAdapter;
import com.jxt.myjxtmanager.utils.ToastUtil;

import java.util.List;

/**
 * Created by qm on 2017/3/6 0006.
 */
public class ClassStateFragment extends BaseFragment implements StuClassShowInter {
    private TableFixHeaders tableFixHeaders;
    private StuClassNexusAdapter stuClassNexusAdapter;
    private List<StuClassShowBean> dataList;
    private StuClassShowPresenter presenter;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_class_state;
    }

    @Override
    protected void initView() {

        tableFixHeaders = (TableFixHeaders) mView.findViewById(R.id.table);
        presenter = new StuClassShowPresenter(getActivity(), this);
        presenter.RequestData();
    }

    @Override
    public void setMyAdapter() {

        presenter.dismissDialog();
        dataList = presenter.getDataList();
        if (stuClassNexusAdapter == null) {
            stuClassNexusAdapter = new StuClassNexusAdapter(getActivity(), getActivity());
//        baseTableAdapter.setDeviceOutLine(presenter.getDeviceOutLine());
            stuClassNexusAdapter.setDevicesDates(dataList);
            tableFixHeaders.setAdapter(stuClassNexusAdapter);
        } else {
            stuClassNexusAdapter.setDevicesDates(dataList);
            stuClassNexusAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public void updateRecycler() {
        dataList = presenter.getDataList();
        stuClassNexusAdapter.setDevicesDates(dataList);
        stuClassNexusAdapter.notifyDataSetChanged();
    }

    @Override
    public void showToastMsg(String msg) {
        if (!TextUtils.isEmpty(msg)) {
            ToastUtil.showToast(getContext(), msg);
        }
    }
}
